var events = require("events");
var EvEm = events.EventEmitter;

function Dog(name,energy) {
    EvEm.call(this);
    this.name=name;
    this.energy=energy;
    this.id;
}
Dog.prototype=EvEm.prototype;
Dog.prototype.bark=function () {
    this.id=setInterval(() => {
        if(this.energy>=0){
            console.log(this.name+" barked!"+` energy:${this.energy}`);
            this.energy--;
        } 
        if(this.energy<0){
            clearInterval(this.id);
        }
    }, 1000);
    
    
}

module.exports=Dog;